const {PLEASE_ENTER_THE_RECHARGE_AMOUNT} = require('../error/errorType')

const { v4 } = require('uuid')
const verifyRecharge = async (ctx, next) => {
  const { amount } = ctx.request.body
  if (!amount) {
    return ctx.app.emit('error', new Error(PLEASE_ENTER_THE_RECHARGE_AMOUNT ), ctx)
   
  }
  //设置订单号 和 支付状态
  let status = Math.round(Math.random()) //0<=x<1
  //用 uuid =》生成唯一的订单号
  let orderNo = (() => v4())()
  const orderInfo = {
    amount,
    orderNo,
    status
  }
  ctx.orderInfo = orderInfo
  await next()
}

module.exports = {
  verifyRecharge
}